/*
 * @Author: mm.yang 
 * @Date: 2018-05-09 16:11:53 
 * @Last Modified by: mm.yang
 * @Last Modified time: 2018-05-11 11:00:26
 */

const Service = require('egg').Service;
class NewsService extends Service {
  async list(page = 1){
    // read config
    console.log('this',this);
    const { serverUrl, pageSize} = this.config.news;

    // http client this.ctx.curl 发起请求
    const newList = await this.ctx.curl(`${serverUrl}/get?foo=bar`, {dataType: 'json'});
    console.log('newList', newList)
    //  get detail
    // const newList = await Promise.all(
    //   Object.keys(idList).map(key => {
    //     const url = `${serverUrl}/get?foo=bar`;
    //     return this.ctx.curl(url, {dataType: 'json'});
    //   })
    // );
    if (newList.status === 200){
      return newList.data
    } else {
      return {
        origin: newList.status,
        url: 'the server is fail'
      }
    }
    return newList.data;
  }
}

module.exports = NewsService;